import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

let router =  new Router({
    linkActiveClass:'active',
    routes: [
        {
            path:'/',
            redirect:'/main/home'
        },
        {
            path:'/login',
            component:() => import('@/views/login')
        },
        {
            path:'/main',
            component:() => import('@/views/main/index'),
            children:[
                {
                    path:'/main/home',
                    component:() => import('@/views/main/home')
                },
                {
                    path:'/main/menu',
                    component:() => import('@/views/main/menu')
                },
                {
                    path:'/main/order',
                    component:() => import('@/views/main/order')
                },
                {
                    path:'/main/car',
                    name:'car',
                    component:() => import('@/views/main/car')
                },
                {
                    path:'/main/my',
                    component:() => import('@/views/main/my')
                }
            ]
        }
    ]
})

// let arr = [''];

router.beforeEach((to,from,next) => {
    if(to.name === 'car'){
        let uid = window.localStorage.getItem('username') ||'';
        if(uid){
            next();
        }else{
            next('/login')
        }
    }else{
        next()
    }
})

export default router



